package com.fdb.efp.nls.service.impl.ed;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.fdb.efp.nls.service.facade.ed.LmtRecoverRecordService;
import com.fdb.efp.nls.service.vo.ed.LmtRecoverRecordVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.ed.LmtRecoverRecordDao;
import com.fdb.efp.nls.service.domain.ed.LmtRecoverRecord;

/**
 * <p>
 * ServiceImpl: 额度恢复记录表
 * <p>
 * 
 * @author ligm
 * @date 2019-03-04
 */
@Service("lmtRecoverRecordService")
public class LmtRecoverRecordServiceImpl implements LmtRecoverRecordService, FrameworkService {
	private static Logger logger = LoggerFactory.getLogger(LmtRecoverRecordServiceImpl.class);

	@Autowired
	private LmtRecoverRecordDao lmtRecoverRecordDao;

	/**
	 * 新增操作
	 */
	public int insertLmtRecoverRecord(LmtRecoverRecordVO inLmtRecoverRecordVo) {
		logger.debug("当前新增数据为:" + inLmtRecoverRecordVo.toString());
		int num = 0;
		try {
			LmtRecoverRecord lmtRecoverRecord = new LmtRecoverRecord();
			beanCopy(inLmtRecoverRecordVo, lmtRecoverRecord);
			num = lmtRecoverRecordDao.insertLmtRecoverRecord(lmtRecoverRecord);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(LmtRecoverRecordVO inLmtRecoverRecordVo) {
		logger.debug("当前删除数据条件为:" + inLmtRecoverRecordVo);
		int num = 0;
		try {
			LmtRecoverRecord lmtRecoverRecord = new LmtRecoverRecord();
			beanCopy(inLmtRecoverRecordVo, lmtRecoverRecord);
			num = lmtRecoverRecordDao.deleteByPk(lmtRecoverRecord);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inLmtRecoverRecordVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	public int updateByPk(LmtRecoverRecordVO inLmtRecoverRecordVo) {
		logger.debug("当前修改数据为:" + inLmtRecoverRecordVo.toString());
		int num = 0;
		try {
			LmtRecoverRecord lmtRecoverRecord = new LmtRecoverRecord();
			beanCopy(inLmtRecoverRecordVo, lmtRecoverRecord);
			num = lmtRecoverRecordDao.updateByPk(lmtRecoverRecord);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inLmtRecoverRecordVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public LmtRecoverRecordVO queryByPk(LmtRecoverRecordVO inLmtRecoverRecordVo) {

		logger.debug("当前查询参数信息为:" + inLmtRecoverRecordVo);
		try {
			LmtRecoverRecord queryLmtRecoverRecord = new LmtRecoverRecord();
			beanCopy(inLmtRecoverRecordVo, queryLmtRecoverRecord);
			LmtRecoverRecord queryRslLmtRecoverRecord = lmtRecoverRecordDao.queryByPk(queryLmtRecoverRecord);
			if (Objects.nonNull(queryRslLmtRecoverRecord)) {
				LmtRecoverRecordVO outLmtRecoverRecordVo = beanCopy(queryRslLmtRecoverRecord, new LmtRecoverRecordVO());
				logger.debug("当前查询结果为:" + outLmtRecoverRecordVo.toString());
				return outLmtRecoverRecordVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtRecoverRecordVO> queryAllOwner(LmtRecoverRecordVO lmtRecoverRecordVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<LmtRecoverRecordVO> list = null;
		try {
			List<LmtRecoverRecord> lmtRecoverRecords = lmtRecoverRecordDao.queryAllOwnerByPage(lmtRecoverRecordVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + lmtRecoverRecords.size());
			pageSet(lmtRecoverRecords, lmtRecoverRecordVo);
			list = (List<LmtRecoverRecordVO>) beansCopy(lmtRecoverRecords, LmtRecoverRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtRecoverRecordVO> queryAllCurrOrg(LmtRecoverRecordVO lmtRecoverRecordVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<LmtRecoverRecord> lmtRecoverRecords = lmtRecoverRecordDao.queryAllCurrOrgByPage(lmtRecoverRecordVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + lmtRecoverRecords.size());
		List<LmtRecoverRecordVO> list = null;
		try {
			pageSet(lmtRecoverRecords, lmtRecoverRecordVo);
			list = (List<LmtRecoverRecordVO>) beansCopy(lmtRecoverRecords, LmtRecoverRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtRecoverRecordVO> queryAllCurrDownOrg(LmtRecoverRecordVO lmtRecoverRecordVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<LmtRecoverRecord> lmtRecoverRecords = lmtRecoverRecordDao.queryAllCurrDownOrgByPage(lmtRecoverRecordVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + lmtRecoverRecords.size());
		List<LmtRecoverRecordVO> list = null;
		try {
			pageSet(lmtRecoverRecords, lmtRecoverRecordVo);
			list = (List<LmtRecoverRecordVO>) beansCopy(lmtRecoverRecords, LmtRecoverRecordVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 
	 * 通过用信申请流水号和账务日期查询额度恢复记录 <br>
	 * 0.1:ludayong:2019年5月24日 上午10:42:41:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年5月24日 上午10:42:41
	 * @date 2019年5月24日 上午10:42:41
	 * @version 0.1
	 */
	public LmtRecoverRecordVO queryByLmtApplySeqAndAccDate(LmtRecoverRecordVO inLmtRecoverRecordVo) {
		logger.debug("当前查询参数信息为:" + inLmtRecoverRecordVo);
		try {
			LmtRecoverRecord queryLmtRecoverRecord = new LmtRecoverRecord();
			beanCopy(inLmtRecoverRecordVo, queryLmtRecoverRecord);
			LmtRecoverRecord queryRslLmtRecoverRecord = lmtRecoverRecordDao.queryByLmtApplySeqAndAccDate(queryLmtRecoverRecord);
			if (Objects.nonNull(queryRslLmtRecoverRecord)) {
				LmtRecoverRecordVO outLmtRecoverRecordVo = beanCopy(queryRslLmtRecoverRecord, new LmtRecoverRecordVO());
				logger.debug("当前查询结果为:" + outLmtRecoverRecordVo.toString());
				return outLmtRecoverRecordVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 开发人员：【chenxuan】
	 * 创建/修改日期：【2019/8/8】
	 * 修改描述：根据身份证、证件类型查询额度恢复金额
	 * @Param [accLoanVO]
	 * @return java.math.BigDecimal
	 **/
	@Override
	public BigDecimal querRecoverAmt(Map<String,String> paramMap) {
		logger.debug("查询额度恢复金额开始:" + paramMap.toString());
		try {
			BigDecimal recoveramt = lmtRecoverRecordDao.querRecoverAmt(paramMap);
			if(recoveramt == null){
				recoveramt = BigDecimal.ZERO;
			}
			logger.debug(paramMap.get("certCode")+"额度恢复金额查询结束，额度恢复金额为:" + recoveramt.toString());
			return recoveramt;
		} catch (Exception e) {
			logger.error("查 询额度恢复金额发生异常!", e);
		}
		return null;
	}
}
